package com.journey.org.app

import android.app.Application
import android.graphics.drawable.Drawable
import androidx.core.content.ContextCompat
import androidx.databinding.ObservableBoolean
import androidx.databinding.ObservableField
import com.journey.org.R
import com.mvvmhabit.org.base.BaseViewModel
import com.mvvmhabit.org.binding.command.BindingAction
import com.mvvmhabit.org.binding.command.BindingCommand
import com.mvvmhabit.org.bus.event.SingleLiveEvent

open class TitleViewModel(application: Application) : BaseViewModel(application) {

    val titleViewModel: TitleViewModel = this

    var toolbarColorBg: Int = ContextCompat.getColor(application, R.color.colorPrimary)

    var toolbarTitleColor: Int = ContextCompat.getColor(application, R.color.white)

    var leftIcon: Drawable? = ContextCompat.getDrawable(application, R.mipmap.ic_white_return_icon)

    val onToolbarTitle = ObservableField("")

    val onToolbarRightTitle = ObservableField("")

    val onToolbarRightVisible = ObservableBoolean(false)

    open val onFinishCommand = BindingCommand<Any>(object : BindingAction {
        override fun call() {
            finish()
        }
    })

    val onClickRightEvent = SingleLiveEvent<Any>()

    open val onClickRightCommand = BindingCommand<Any>(object : BindingAction {
        override fun call() {
            onClickRightEvent.call("")
        }
    })

    fun setWhiteTheme(title: String) {
        onToolbarTitle.set(title)
        toolbarColorBg = ContextCompat.getColor(getApplication(), R.color.white)
        toolbarTitleColor = ContextCompat.getColor(getApplication(), R.color.black)
        leftIcon = ContextCompat.getDrawable(getApplication(), R.mipmap.ic_white_return_icon)
    }

}